//
//  Rps.swift
//  石头剪子布
//
//  Created by adiljan on 16/8/30.
//  Copyright © 2016年 adiljan. All rights reserved.
//

import Foundation


struct Rps{
    private var stat:Stats!
    enum Stats {
        case Rock
        case Scissor
        case Paper
    }
    
    func getStats() -> Stats {
        return stat
    }
    mutating func setStats(stats:Stats) {
        stat = stats
    }
    
    func randomRps() -> Stats { // 生成一个随机手势
        let randomNumber = arc4random_uniform(3)
        var randomStat:Stats!
        switch randomNumber {
        case 0:
            randomStat = .Rock
        case 1:
            randomStat = .Scissor
        case 2:
            randomStat = .Paper
            
        default:
            print("Error")
            
        }
        return randomStat
    }
    func compare(aRpsStat:Stats,anotherRpsStat:Stats) -> Int {
        // 返回三种状态  0：输  1：赢  2：平局
        var result:Int
        switch aRpsStat {
        case .Rock:
            switch anotherRpsStat {
            case .Rock:
                result = 2
            case .Scissor:
                result = 1
            case .Paper:
                result = 0
                
            }
        case .Scissor:
            switch anotherRpsStat {
            case .Rock:
                result = 0
            case .Scissor:
                result = 2
            case .Paper:
                result = 1
                
            }
        case .Paper:
            switch anotherRpsStat {
            case .Rock:
                result = 1
            case .Scissor:
                result = 0
            case .Paper:
                result = 2
                
            }
            
        }
        return result
    }
}